package com.nowcoder.code.lcof;

import java.util.ArrayList;

public class JZ74 {

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(new JZ74().FindContinuousSequence(i).toString());
        }
    }

    public ArrayList<ArrayList<Integer>> FindContinuousSequence(int sum) {

        ArrayList<ArrayList<Integer>> list = new ArrayList<>();

        int max = (sum >> 1) + 1;

        int start = 1;
        int end = 2;
        int tmpSum = 3;

        while (end <= max) {
            if (tmpSum == sum) {
                if (start < end) {
                    ArrayList<Integer> list1 = new ArrayList<>();
                    for (int i = start; i <= end; i++) {
                        list1.add(i);
                    }
                    list.add(list1);
                }
                end++;
                tmpSum = tmpSum + end;
            } else if ( tmpSum < sum) {
                end++;
                tmpSum = tmpSum + end;
            } else {
                tmpSum = tmpSum - start;
                start++;
            }
        }

        return list;

    }
}
